const fs = require('fs');

const fileName = __dirname + '/fsdir2/demo.txt';
const fileWriteName = __dirname + '/fsdir2/demo2.txt';
console.log(fileName)
const readStream = fs.createReadStream(fileName,{highWaterMark:1});
let data = ''
readStream.on('data',(chunk)=>{
    data = data + chunk;
   
})
readStream.on('end',(chunk)=>{
    console.log('file read end')
    const writeStream = fs.createWriteStream(fileWriteName);
    writeStream.write(data, () => {
        console.log('数据写完了000')
    })
    writeStream.on('close', (fd) => { // 文件写入操作完成后触发
        console.log('文件关闭了', fd)
    })
    
    writeStream.end() // 执行代表写入完成
    
    writeStream.on('end', () => { // 执行之后意味着数据写入操作完成
        console.log('当数据被清空之后')
    })
})
readStream.on('error',(err)=>{
    console.log(err)
})


